//
//  ByViewGoodsName.m
//  mijifen_ios
//
//  Created by mc on 2017/11/1.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewGoodsName.h"

// other
#import "ByTextView.h"

@interface ByViewGoodsName()<UITextViewDelegate>
@end

@implementation ByViewGoodsName
{
    UIView      *_contentView;
    ByTextView  *_nameTextView;
    UILabel     *_countLabel;
}
- (instancetype)init{
    if (self = [super init]) {
        self.backgroundColor = [UIColor whiteColor];
        [self createViews];
    }
    return self;
}

- (void)createViews{
    _contentView = [[UIView alloc] init];
    [self addSubview:_contentView];
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.top.equalTo(self.mas_top);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 195));
    }];
    _contentView.backgroundColor = [UIColor darkGrayColor];
    
    _nameTextView = [[ByTextView alloc] init];
    [self addSubview:_nameTextView];
    [_nameTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.top.equalTo(_contentView.mas_bottom).offset(10);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 20, 50));
    }];
    _nameTextView.placeholder = @"输入商品名称";
    _nameTextView.font = FONT(16);
    _nameTextView.delegate = self;
    
    _countLabel = [[UILabel alloc] init];
    [self addSubview:_countLabel];
    CGFloat width = [@"0/48" getSizeOfString:16].width + 10;
    [_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-10);
        make.top.equalTo(_nameTextView.mas_bottom).offset(5);
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    _countLabel.textAlignment = NSTextAlignmentRight;
    _countLabel.textColor = [UIColor lightGrayColor];
}

- (void)textViewDidEndEditing:(UITextView *)textView{
    if (self.nameEditBlock) {
        self.nameEditBlock(textView.text);
    }
}
@end
